#include <iostream>

#include "CNode.h"
#include "CBeam.h"
#include "CStructure.h"

using namespace std;

int main()
{
    /*CNode *n0=new CNode(0, 0., 0., 0.);
    CNode *n1=new CNode(1, 1., 0., 0.);
    CNode *n2=new CNode(2, 2., 0., 0.);
    CNode *n3=new CNode(3, 0., 0., 1.);
    CNode *n4=new CNode(4, 2., 0., 1.);
    CNode *n5=new CNode(5, 0., 0., 2.);
    CNode *n6=new CNode(6, 1., 0., 2.);
    CNode *n7=new CNode(7, 2., 0., 2.);
    CNode *n8=new CNode(8, 0., 1., 0.);
    CNode *n9=new CNode(9, 0., 2., 0.);
    CNode *n10=new CNode(10, 0., 2., 1.);
    CNode *n11=new CNode(11, 0., 1., 2.);
    CNode *n12=new CNode(12, 0., 2., 2.);
    CNode *n13=new CNode(13, 1., 2., 2.);
    CNode *n14=new CNode(14, 2., 1., 2.);
    CNode *n15=new CNode(15, 2., 2., 2.);

    CBeam *b0=new CBeam(n0,n1);
    CBeam *b1=new CBeam(n1,n2);
    CBeam *b2=new CBeam(n0,n3);
    CBeam *b3=new CBeam(n3,n5);
    CBeam *b4=new CBeam(n2,n4);
    CBeam *b5=new CBeam(n4,n7);
    CBeam *b6=new CBeam(n0,n8);
    CBeam *b7=new CBeam(n8,n9);
    CBeam *b8=new CBeam(n9,n10);
    CBeam *b9=new CBeam(n10,n12);
    CBeam *b10=new CBeam(n5,n11);
    CBeam *b11=new CBeam(n12,n11);
    CBeam *b12=new CBeam(n5,n6);
    CBeam *b13=new CBeam(n6,n7);
    CBeam *b14=new CBeam(n12,n13);
    CBeam *b15=new CBeam(n13,n15);
    CBeam *b16=new CBeam(n14,n15);
    CBeam *b17=new CBeam(n14,n7);

    b0->setProperties(1.,1.,1.,1.,1.);
    b1->setProperties(1.,1.,1.,1.,1.);
    b2->setProperties(1.,1.,1.,1.,1.);
    b3->setProperties(1.,1.,1.,1.,1.);
    b4->setProperties(1.,1.,1.,1.,1.);
    b5->setProperties(1.,1.,1.,1.,1.);
    b6->setProperties(1.,1.,1.,1.,1.);
    b7->setProperties(1.,1.,1.,1.,1.);
    b8->setProperties(1.,1.,1.,1.,1.);
    b9->setProperties(1.,1.,1.,1.,1.);
    b10->setProperties(1.,1.,1.,1.,1.);
    b11->setProperties(1.,1.,1.,1.,1.);
    b12->setProperties(1.,1.,1.,1.,1.);
    b13->setProperties(1.,1.,1.,1.,1.);
    b14->setProperties(1.,1.,1.,1.,1.);
    b15->setProperties(1.,1.,1.,1.,1.);
    b16->setProperties(1.,1.,1.,1.,1.);
    b17->setProperties(1.,1.,1.,1.,1.);

    CStructure *s=new CStructure();
    s->addBeam(b0);
    s->addBeam(b1);
    s->addBeam(b2);
    s->addBeam(b3);
    s->addBeam(b4);
    s->addBeam(b5);
    s->addBeam(b6);
    s->addBeam(b8);
    s->addBeam(b9);
    s->addBeam(b10);
    s->addBeam(b11);
    s->addBeam(b12);
    s->addBeam(b13);
    s->addBeam(b14);
    s->addBeam(b15);
    s->addBeam(b16);
    s->addBeam(b17);
    s->addBeam(b7);

    n0->setDisplacement(X,0.);
    n0->setDisplacement(Y,0.);
    n0->setDisplacement(Z,0.);
    n0->setDisplacement(ROTX,0.);
    n0->setDisplacement(ROTY,0.);
    n0->setDisplacement(ROTZ,0.);

    n15->setForce(Z,-0.1);

    //n5->setDisplacement(X,1.);
    //n5->setDisplacement(Y,1.);
    //n5->setDisplacement(ROT,1.);

    //n5->setUnknownForce(n1);
    //n3->setRestriction(Y);
    //n4->setRestriction(ROT);
    //n2->setRestriction(X);

    //s->solveOptimized();

    s->assemble();

    s->solve();*/

    /*CNode *n0=new CNode(0, 0., 0., 0.);
    CNode *n1=new CNode(1, 0., 1., 0.);
    CNode *n2=new CNode(2, 1., 0., 0.);
    CNode *n3=new CNode(3, 0., 0., 1.);
    CNode *n4=new CNode(4, 1., 0., 1.);
    CNode *n5=new CNode(5, 2., 0., 2.);
    CNode *n6=new CNode(6, 2., 1., 2.);
    CNode *n7=new CNode(7, 3., 1., 2.);
    CNode *n8=new CNode(8, 3., 1., 3.);
    CNode *n9=new CNode(9, 2., 1., 3.);

    CBeam *b0=new CBeam(n0,n1);
    CBeam *b1=new CBeam(n0,n3);
    CBeam *b2=new CBeam(n0,n2);
    CBeam *b3=new CBeam(n2,n3);
    CBeam *b4=new CBeam(n2,n4);
    CBeam *b5=new CBeam(n3,n4);
    CBeam *b6=new CBeam(n4,n5);
    CBeam *b7=new CBeam(n5,n6);
    CBeam *b8=new CBeam(n6,n7);
    CBeam *b9=new CBeam(n6,n8);
    CBeam *b10=new CBeam(n6,n9);
    CBeam *b11=new CBeam(n9,n8);
    CBeam *b12=new CBeam(n8,n7);

    b0->setProperties(1.,1.,1.,1.,1.);
    b1->setProperties(1.,1.,1.,1.,1.);
    b2->setProperties(1.,1.,1.,1.,1.);
    b3->setProperties(1.,1.,1.,1.,1.);
    b4->setProperties(1.,1.,1.,1.,1.);
    b5->setProperties(1.,1.,1.,1.,1.);
    b6->setProperties(1.,1.,1.,1.,1.);
    b7->setProperties(1.,1.,1.,1.,1.);
    b8->setProperties(1.,1.,1.,1.,1.);
    b9->setProperties(1.,1.,1.,1.,1.);
    b10->setProperties(1.,1.,1.,1.,1.);
    b11->setProperties(1.,1.,1.,1.,1.);
    b12->setProperties(1.,1.,1.,1.,1.);

    CStructure *s=new CStructure();
    s->addBeam(b0);
    s->addBeam(b1);
    s->addBeam(b2);
    s->addBeam(b3);
    s->addBeam(b4);
    s->addBeam(b5);
    s->addBeam(b6);
    s->addBeam(b7);
    s->addBeam(b8);
    s->addBeam(b9);
    s->addBeam(b10);
    s->addBeam(b11);
    s->addBeam(b12);

    n0->setDisplacement(X,0.);
    n0->setDisplacement(Y,0.);
    n0->setDisplacement(Z,0.);
    n0->setDisplacement(ROTX,0.);
    n0->setDisplacement(ROTY,0.);
    n0->setDisplacement(ROTZ,0.);

    n8->setForce(Z,0.1);

    //n7->setUnknownForce(n0);
    //n5->setRestriction(Z);

    n7->setForce(X,-0.263415);
    n7->setForce(Y,-0.087805);
    n7->setForce(Z,-0.175610);

    s->assemble();

    s->solve();*/

    CStructure *s=new CStructure();
    s->parseInputFile("struct.txt");
    s->solveOptimized();
    s->writeAnsysFile("solution.txt");

    return 0;
}
